package com.qlslylq.ad.sdk.util;

import android.content.Context;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;

import com.qlslylq.ad.sdk.R;

import static android.text.TextUtils.isEmpty;

/**
 * created by qlslylq <br/>
 */
public class ToastUtils {

    /**
     * 显示长Toast<br/>
     */
    public static void showToast(Context context, String text) {
        if (!isEmpty(text)) {
            Toast toast = Toast.makeText(context, text, Toast.LENGTH_LONG);
            if (toast.getView() != null && toast.getView() instanceof LinearLayout) {
                LinearLayout toastView = (LinearLayout) toast.getView();
                toastView.setBackgroundResource(R.drawable.bg_toast);
                TextView textView = (TextView) toastView.getChildAt(0);
                textView.setPadding(0, 0, 0, 0);
                textView.setText(text);
            }
            toast.show();
        }
    }

    /**
     * 显示短Toast<br/>
     */
    public static void showShortToast(Context context, String text) {
        if (!isEmpty(text)) {
            Toast toast = Toast.makeText(context, text, Toast.LENGTH_SHORT);
            if (toast.getView() != null && toast.getView() instanceof LinearLayout) {
                LinearLayout toastView = (LinearLayout) toast.getView();
                toastView.setBackgroundResource(R.drawable.bg_toast);
                TextView textView = (TextView) toastView.getChildAt(0);
                textView.setPadding(0, 0, 0, 0);
                textView.setText(text);
            }
            toast.show();
        }
    }
}
